<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .login-container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
        }
        .login-container h2 {
            margin-bottom: 20px;
            text-align: center;
        }
        .login-container input[type="text"],
        .login-container input[type="password"] {
            width: 280px;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .login-container button {
            width: 100%;
            padding: 10px;
            background-color: #28a745;
            border: none;
            border-radius: 4px;
            color: white;
            font-size: 16px;
            cursor: pointer;
        }
        .login-container button:hover {
            background-color: #218838;
        }
        .error-message {
            color: red;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <h2>登录</h2>
        <div class="error-message" id="error-message"></div>
        <input type="text" id="username" placeholder="用户名" required>
        <input type="password" id="password" placeholder="密码" required>
        <button id="submit">登录</button>
    </div>

<!--    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>-->
    <script src="/static/js/axios.min.js"></script>
 <script>
        //绑定一个点击事件
        document.getElementById("submit").onclick = function () {
            //获取用户名密码
            let number = document.getElementById("username").value;
            let password = document.getElementById("password").value;
            const url="http://localhost:8080/login";
            const data={
                    number:number,
                    password:password
            }

            axios
                .post(url,data)
                .then(function (response) {
                if (response.data.code==200){
                    //登录成功,跳转到
                    window.location.href="./home.html";
                }else {
                    //登录失败
                    document.getElementById("error-message").innerHTML=response.data.message;
                }
            })
        }
</script>
</body>
</html>
